<?php 

namespace app\common\shop;

use think\Db;
use think\Model;
use traits\model\SoftDelete;


class ArticleCateModel extends model {
    //use SoftDelete;//开启了软删除
    //protected  = 'del_time';
    // 完整数据表名
    protected $table = 'article_cate';


    /**
     * [建表]
     * @return
     */
    public static function createTable(){
        return Db::query("CREATE TABLE If Not Exists `article_cate` (
             `id` int(11) NOT NULL AUTO_INCREMENT,
             `title` varchar(255) NOT NULL COMMENT '分类标题',
             `createtime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
             PRIMARY KEY (`id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章分类表'");
    }

    /**
     * [添加]
     * @return
     */
    public static function add($data){
        $data['createtime'] = time();
        return self::insertGetId($data);
    }
    /**
     * [修改]
     * @return
     */
    public static function edit($data,$id){
        return self::where('id',$id)->update($data);
    }
    /**
     * [处理数据]
     * @param $input
     * @return
     */
    public static function dispose($input,$id='' ){
        $goods_data = [
            'title'=>$input['title'],//标题
        ];
        if($id){
            self::edit($goods_data,$id);// 修改
        }else{
            $id = self::add($goods_data);//添加
        }
        return $id;
    }

}
